<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="/css/common.css" />
		<link rel="stylesheet" type="text/css" href="/js/flatpickr.min.css" />
		<link rel="stylesheet" type="text/css" href="/bootstrap-3.3.7/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="/dialog/css/dialog.css" />
		<link rel="stylesheet" type="text/css" href="/css/font-awesome.css" />

        <script src="/js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="/js/google-maps.js" type="text/javascript" charset="utf-8"></script>
        <script src="/js/jquery.form.js"></script>
        <script src="/dialog/js/dialog.js"></script>
        <script src="/js/jquery.validate.min.js"></script>
        <script src="/js/messages_zh.min.js"></script>

        <script src="/js/common.js"></script>
		<script src="/js/flatpickr.js"></script>
        <script type="text/javascript">
            function delete1(id) {
                $.ajax({
                    type:'post',
                    url:'delete',
                    data:{
                        id : id
                    },
                    success:function (data) {
                        if(data.code == 0){
                            window.location.reload();
                        }else{
                            alert("删除失败");
                        }
                    }
                });
            }

            function inquiry() {
                var routeId = $("#routeId").val();
                var stationNo = $("#stationNo").val();

                $.ajax({
                    type:'post',
                    url:'inquiry',
                    data:{
                        routeId : routeId,
                        stationNo : stationNo
                    },
                    success:function(json){
                        var tbody = $("#tbody");
                        tbody.children('tr').remove();
                        console.log(json);
                        $.each(json.data , function (n,route) {
                            var data1 = '<tr>'+
                                    '<th width="40"><input value="'+route.routeId+'" type="checkbox"/></th>'+
                                    '<th width="100">'+route.routeId+'</th>'+
                                    '<th width="150">'+route.routeName+'</th>'+
                                    '<th width="150">'+route.stationName+'</th>'+
                                    '<th width="100">'+route.stationNo+'</th>'+
                                    '<th width="100">'+route.remark+'</th>'+
                                    '<th width="100"><input type="button"  value="编辑"/><input type="button" value="删除" onclick="JavaScript:if(confirm(&apos;是否删除&apos;)) { delete1('+route.routeId+')}"/></th>'+
                                    '</tr>';
                            tbody.append(data1);
                        });
                    }
                });
            }

            </script>
	</head>

	<body>
		<!--顶部导航 -->
		<nav class="topNavItemBox">
			<div id="ItemBox">
				<div class="title">肉品溯源管理系统</div>
			</div>
		</nav>
		<!-- 左侧导航 -->
		<#include "left.ftl"/>

        <!--物流线路信息查询 -->

		<div class="page_main">
			<h3>线路管理</h3><span class="add_link"><a href="/admin/transportRouteInfor/add">新增线路信息></a></span>
			<br />
			<div class="page_content">
				<h4>线路查询</h4>
				<br />
				<form id="transportInfo_query" method="post" action="/admin/transportRouteInfor/list">
                    <label>线路序号</label><input type="text" id="routeId" name="routeId" value="${routeId}" class="commonInputtext" /><span></span>
                    <label>站点序号</label><input type="text" id="stationNo" name="stationNo" value="${stationNo}" class="commonInputtext" />
					<input type="submit" value="查询"  style="display: inline-block; margin-left: 50px;" />
				</form>
				<div>
					<table id="transport_table" class="table" width="100%">
						<thead>
							<tr>
								<th width="40"><input id="checkall" type="checkbox" /></th>
								<th width="100">线路序号</th>
								<th width="150">线路名称</th>
								<th width="150">站点名称</th>
								<th width="100">站点序号</th>
								<th width="100">备注</th>
								<th width="100">操作</th>
							</tr>
						</thead>
						<tbody id="tbody">
							<#list page.list as route>
								<tr>
									<th width="40"><input value="${route.routeId}" type="checkbox"/></th>
										<th width="100">${route.routeId}</th>
										<th width="150">${route.routeName}</th>
										<th width="150">${route.stationName}</th>
										<th width="100">${route.stationNo}</th>
										<th width="100">${route.remark}</th>
										<th width="100"><input type="button"  value="编辑"/><input type="button" value="删除" onclick="JavaScript:if(confirm(&apos;是否删除&apos;)) { delete1(${route.routeId})}"/></th>
								</tr>
							</#list>
						</tbody>
					</table>
				</div>
				<div id="barcon" name="barcon" style="margin-left: 200px;font-size:10px"></div>
				<input type="button" id="deleteAllchoice" value="删除所选" style="display:none">
			</div>
			<div class="footer">
				<div class="footer_lineone">
					<span id="logo"></span>肉品溯源管理系统 
					<span class="footer_lineoneSpan"><a href="aboutus.html">关于我们</a></span>
					<span class="footer_lineoneSpan"><a target="_blank" href="http://www.cfsiw.com/">食品安全信息</a></span> 
					<span class="footer_lineoneSpan"><a href="suggestionAdd.ftl">联系我们</a></span>
				</div>
				<div class="footer_linetwo">
					 &copy;2017广东技术师范学院
				</div>
			</div>
		</div>


		</script>
		<script type="text/javascript" charset="UTF-8">
			$(function() {
				//初始化侧边栏
				$(".vertical-nav").verticalnav({
					speed: 400,
					align: "left"
				});

				var re_data; //每次传过来的数据
				//查询
				$("#transportInfo_query").ajaxForm(function(data) {
					console.log(data);
					re_data = data;
					$("#transport_table tbody tr").remove();
					for(var i = 0; i < data.length; i++) {
						var tb = $("#transport_table tbody");
						var td_head = '<tr id="transport_row' + data[i].routeId + '">';
						var td1 = '<td><input type="checkbox" name="selectRows" class="isCheck" value="' + data[i].routeId + '"/></td>';
						var td2 = '<td>' + data[i].routeId + '</td>';
						var td3 = '<td>' + data[i].routeName + '</td>';
						var td4 = '<td>' + data[i].stationName + '</td>';
						var td5 = '<td>' + data[i].stationNo + '</td>';
						if( data[i].remark ==""){
							var td6 = '<td style="color:#D3D3D3;">暂无备注</td>';
						}else{
							var td6 = '<td>'+ data[i].remark +'</td>';
						}
						var td7 = '<td><input type="button" onclick="updateData(' + i + ')" class="change" value="更改" style="padding:0 5px"/><input type="button" value="删除" onclick="deleteData(' + data[i].routeId + ')" style="padding:0 5px" /></td>'
						var tr_add = td_head + td1 + td2 + td3 + td4 + td5 + td6 + td7 + '</tr>'
						tb.append(tr_add);
					}
					$("#no_data").remove();
					$("#deleteAllchoice").css("display", "block");
					goPage(1, 4, "transport_table");
				});

				//多选
				$("#checkall").click(function() {
					$('input[class="isCheck"]').attr("checked", this.checked);
				});
				var $isCheck = $("input[class='isCheck']");
				$isCheck.click(function() {
					$("#checkall").attr("checked", $isCheck.length == $("input[class='isCheck']:checked").length ? true : false);
				});

				//删除

				function deleteByids(delete_data) {
					$.dialog({
						type: 'confirm',
						contentHtml: '<p style:"magrin:0 auto">确认删除？</p>',
						onClickOk: function() {
							$.ajax({
								url: "TransportRouteAction_deleteTransportRouteInfo",
								data: {
									'selectRows': delete_data
								},
								success: function() {
									var chrstr = delete_data.split(",");
									console.log(chrstr);
									console.log($("#transport_row" + chrstr[0]));
									for(i = 0; i < chrstr.length; i++) {
										$("#transport_row" + chrstr[i]).remove();
									}
								}
							});
						}
					});

				}
				deleteData = function(i) {
					var st = i;
					st += ",";
					deleteByids(st);
				}
				$("#deleteAllchoice").click(function() {
					delete_data = get_checkbox_data();
					deleteByids(delete_data);
				});

				function get_checkbox_data() {
					var data_temp = "";
					$("input[class='isCheck']:checked").each(function() { // 遍历选中的checkbox
						data_temp += $(this).val() + ',';
						console.log(data_temp);
					});
					return data_temp;

				}

				//更改

				updateData = function(i) {
					var row0 = '<form id="transport_updateform" action="TransportRouteAction_updateTransportRouteInfo" method="post">'

					var row1 = '<li><label class="labelBeforinput">线路序号</label><input name="routeId" class="bigInputtext" readOnly="true" type="text" value="' + re_data[i].routeId + '" /></li>';
					var row2 = '<li><label class="labelBeforinput">线路名称</label><input name="routeName" data-rule-chinese="true" class="bigInputtext" type="text" value="' + re_data[i].routeName + '"/></li>';
					var row3 = '<li><label class="labelBeforinput">站点名称</label><input name="stationNo" class="bigInputtext" type="text" value="' + re_data[i].stationNo + '"/></li>';
					var row4 = '<li><label class="labelBeforinput">站点序号</label><input name="stationName" class="bigInputtext" type="text" value="' + re_data[i].stationName + '" /></li>';
					
					if(re_data[i].remark==""){
						var row5 = '<li><label class="labelBeforinput">备注</label><input name="remark" class="bigInputtext" type="text" placeholder="暂无数据" /></li>';
					}else{
						var row5 = '<li><label class="labelBeforinput">备注</label><input name="remark" class="bigInputtext" type="text" value="' + re_data[i].remark + '" /></li>';
					}
					var rowLast = '</form>'
					var str = row0 + row1 + row2 + row3 + row4 + row5 + rowLast;
					$.dialog({
						type: 'confirm',
						titleText: '更改数据',
						contentHtml: str,
						onClickOk: function() {
							$("#transport_updateform").ajaxSubmit({
								type: 'post',
								success: function(data) {
									//成功弹窗
									$.dialog({
										type: 'info',
										contentHtml: '<img class="info-icon" src="dialog/images/icon/success.png" alt="更新成功" /><p class="info-text">更新成功</p>',
										autoClose: 2000
									});
									console.log(data);
									var row = $("#transport_row" + data.transportrouteInfor.routeId);
									row.find("td").eq(1).text(data.transportrouteInfor.routeId);
									row.find("td").eq(2).text(data.transportrouteInfor.routeName);
									row.find("td").eq(3).text(data.transportrouteInfor.stationName);
									row.find("td").eq(4).text(data.transportrouteInfor.stationNo);
									if(data.transportrouteInfor.remark==""){
										$('#remark').css("color","D3D3D3");
										row.find("td").eq(5).text("暂无备注").css("color","#D3D3D3");
									}else{
										$('#remark').css("color","");
										row.find("td").eq(5).text(data.transportrouteInfor.remark).css("color","black");
									}
									re_data[i] = data.transportrouteInfor;
								}

							});
						}

					});
				}

			});
		</script>

	</body>

</html>